package CutLoad.transitions.fireworks
{
	import flash.display.GradientType;
	import flash.display.Sprite;
	
	public class FireUnit extends Sprite
	{
		public static  var FIRE_TYPE_BALL:Number=1;
		public static  var FIRE_TYPE_SPLASH:Number=2;
		public static  var FILE_TYPE_STAR:Number=3;
		private static var INIT_ALPHA:Number=0.5;
		private var dType:Number;
		private var dColor:Number;
		private var dAlpha:Number=0;
		private var moveX:Number;
		private var moveY:Number;
		private var paintX:Number=0;
		public function FireUnit(type:Number,color:Number) {
			reinit(type,color);
		}
		public function reinit(type:Number,color:Number):void {
			this.dType=type;
			this.dColor=color;
			reset();
		}
		public function reset():void {
			this.alpha=1;
			this.rotation=0;
			this.visible=false;
			paintX=0;
			paint();
		}
		public function startMove(initSpeed:Number=50,angle:Number=0):void {
			this.dAlpha=0.1;
			this.rotation=angle;
			var t:Number=Math.PI*angle/180;
			this.scaleX=this.scaleY=initSpeed/50;
			moveX=initSpeed*Math.cos(t);
			moveY=initSpeed*Math.sin(t);
		}
		public function loop():void{
			if(dAlpha==0) return;
			if (this.alpha>0) {
				var t:Number=this.alpha-dAlpha;
				if (t<0) {
					t=0;
				}
				this.alpha=t;
			}
			if (this.alpha==0) {
				return;
			}
			this.x+=moveX;
			this.y+=moveY;
			moveX=moveX*3/4;
			moveY=moveY*3/4;
			this.visible=true;
		}
		private function paint():void{
			this.graphics.clear();
			switch (dType) {
				case FIRE_TYPE_BALL :
					this.graphics.beginGradientFill(GradientType.RADIAL,new Array(dColor,dColor),new Array(INIT_ALPHA,0),new Array(0,30));
					this.graphics.drawCircle(5,0,30);
					this.graphics.endFill();
					break;
				case FIRE_TYPE_SPLASH :
					this.graphics.beginFill(dColor,INIT_ALPHA);
					this.graphics.drawEllipse(0,0,25,4);
					this.graphics.endFill();
					break;
				case FILE_TYPE_STAR :
					this.graphics.lineStyle(1,dColor,INIT_ALPHA);
					this.graphics.moveTo(0,-5);
					this.graphics.lineTo(0,5);
					this.graphics.moveTo(-5,0);
					this.graphics.lineTo(5,0);
					break;
			}
		}
	}
}